const { deepClone } = require('../utils')
import asyncRoutes from './routes.js'
const Mock = require('mockjs')

const routes = deepClone([...asyncRoutes])

const menuPermission = [
    {id: 1, pid: 0, path: '/dashboard', name: 'Dashboard', component:'/dashboard/DashboardIndex' , title: '首页大屏', icon: '&#xe657;', type: 2, prouter: 0, isuse: true, isshow: true, desc: '', permission: true},
    {id: 2, pid: 0, path: '/setting', name: 'Setting', component:null, title: '设置', icon: '&#xe66a;', type: 1, prouter: 0,isuse: true, isshow: true,desc: '', permission: true},
    {id: 3, pid: 2, path: '/setting/menusetting', name: 'MenuSetting',component: null , title: '菜单设置', icon: '', type: 1, prouter: 2,isuse: true, isshow: true,desc: '', permission: true},
    {id: 4, pid: 2, path: '/setting/permission', name: 'Permission',component: null , title: '权限设置', icon: '', type: 1, prouter: 2,isuse: true, isshow: true,desc: '', permission: false},
    {id: 5, pid: 4, path: '/permission/rolesetting', name: 'RoleSetting',component: '/permission/RoleSetting' , title: '角色管理', icon: '', type: 2, prouter: 4,isuse: true, isshow: true,desc: '', permission: false},
    {id: 6, pid: 4, path: '/permission/usersetting', name: 'Usersetting',component: '/permission/UserSetting' , title: '用户管理', icon: '', type: 2, prouter: 4,isuse: true, isshow: true,desc: '', permission: false},
    {id: 7, pid: 3, path: '/setting/menusetting/childmenusetting', name: 'childmenusetting',component: '/setting/MenuSetting' , title: '菜单管理', icon: 'i', type: 2, prouter: 3,isuse: true, isshow: true,desc: '', permission: true},
    {id: 8, pid: 2, path: '/setting/table', name: 'testTable',component: '/tabletest/TableList' , title: '测试表格', icon: '', type: 2, prouter: 2,isuse: true, isshow: true,desc: '', permission: false},
    {id: 9, pid: 8, path: '/setting/table/add', name: 'addTable',component: '/tabletest/AddTable' , title: '表格添加', icon: '', type: 3, prouter: 2,isuse: true, isshow: true,desc: '', permission: false},
    {id: 9, pid: 8, path: '/setting/table/remove', name: 'editTable',component: null , title: '表格删除', icon: '', type: 4, prouter: 2,isuse: true, isshow: true,desc: '', permission: false},
    {id: 10, pid: 0, path: '/content', name: 'allContent',component: '/content/AllContent' , title: '内容', icon: '&#xe66c;', type: 2, prouter: 0,isuse: true, isshow: true, desc: '', permission: false},
]

export default [
    // 获取菜单表
    {
        url: '/auth/menu/routes',
        type: 'get',
        data: (req) => {
            // 输出请求参数
            if(process.env.NODE_ENV === 'development') console.log('请求的参数', req);
            return {
                code: 20000,
                data: routes
            }
        }
    },
    // 获取对应id 功能列表
    {
        url: '/auth/menu/getFunc',
        type: 'get',
        data: () => {
            return {
                code: 20000,
                data: [
                    // name命名规则  功能+模块
                    {id: 7, pid: 6, path: '/setting/table/add', name: 'addTable',component: '/tabletest/AddTable' , title: '表格添加', icon: 'i', type: 3, prouter: 2},
                    {id: 8, pid: 6, path: '/setting/table/edit', name: 'editTable',component: '/tabletest/EditTable' , title: '表格修改', icon: 'i', type: 3, prouter: 2},
                    {id: 9, pid: 6, path: '/setting/table/remove', name: 'editTable',component: '/tabletest/RemoveTable' , title: '表格删除', icon: 'i', type: 4, prouter: 2},
                ]
            }
        }
    },
    // 添加菜单和功能
    {
        url: '/auth/menu/add',
        type: 'post',
        data: () => {
            return{
                code: 20000,
                message: 'success'
            }
        }
    },
    // 编辑菜单和功能
    {
        url: '/auth/menu/edit',
        type: 'post',
        data: () => {
            return{
                code: 20000,
                message: 'success'
            }
        }
    },
    // 删除菜单或功能
    {
        url: '/auth/menu/delete',
        type: 'post',
        data: () => {
            return{
                code: 20000,
                message: 'success'
            }
        }
    },
    // 获取角色列表
    {
        url: '/auth/role/roleList',
        type: 'get',
        data: () => {
            return {
                code: 20000,
                data: Mock.mock({
                    'list|15':[
                        {
                            'id|+1': 1,
                            name: '@word(5,10)',
                            title: '@ctitle(4,8)'
                        },
                    ],
                    total: 100,
                    currentPage: 1,
                    pageSize: 15
                })
            }
        }
    },
    // 添加角色
    {
        url: '/auth/role/add',
        type: 'post',
        data: () => {
            return{
                code: 20000,
                message: 'success'
            }
        }
    },
    // 编辑角色
    {
        url: '/auth/role/edit',
        type: 'post',
        data: () => {
            return{
                code: 20000,
                message: 'success'
            }
        }
    },
    //删除角色
    {
        url: '/auth/role/delete',
        type: 'post',
        data: () => {
            return{
                code: 20000,
                message: 'success'
            }
        }
    },
    // 获取角色菜单权限
    {
        url: '/auth/role/menu/permission',
        type: 'get',
        data: () => {
            return{
                code: 20000,
                data: menuPermission
            }
        }
    },
    // 设置角色权限
    {
        url: '/auth/role/menu/setPermission',
        type: 'post',
        data: () => {
            return{
                code: 20000,
                message: 'success'
            }
        }
    },
    // 获取默认角色权限(新建角色时)
    {
        url: '/auth/role/menu/permission/default',
        type: 'get',
        data: () => {
            return{
                code: 20000,
                data: menuPermission
            }
        }
    },
    // 设置默认角色权限
    {
        url: '/auth/role/menu/setDefaultPermission',
        type: 'post',
        data: () => {
            return{
                code: 20000,
                message: 'success'
            }
        }
    }
]
